/* ====================================================================
 * The UncleGED Open Source Software License
 *
 * Copyright (c) 1999-2003 D. M. DeBacker. All rights reserved.
 * http://gatheringleaves.org/uged
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. Products derived from this software may not be called "UncleGED",
 *    nor may "UncleGED" appear in their name, without prior written
 *    permission of D. M. DeBacker.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL D. M. DEBACKER BE LIABLE FOR ANY 
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 */

using System;
using System.IO;
using System.Collections;

namespace UGed
{
	//===============================
	public class Statistics 
	{

		private ArrayList mvarDataList;

		public Statistics () 
		{
			mvarDataList = new ArrayList();
		}

		public void Add( double newItem) 
		{
			mvarDataList.Add(newItem);
		}

		public double Min  
		{
			get 
			{
				return m_Min();
			}
		}
		public double Max  
		{
			get 
			{
				return m_Max();
			}
		}

		public double Mean  
		{
			get 
			{
				return m_Mean();
			}
		}

		public double Median  
		{
			get 
			{
				return m_Median();
			}
		}

//		public double Variance  
//		{
//			get 
//			{
//				return m_Variance();
//			}
//		}
		public double Sum  
		{
			get 
			{
				return m_Total();
			}
		}
//		public double StandardDeviation  
//		{
//			get 
//			{
//				return m_StdDev();
//			}
//		}
		public double AverageDeviation  
		{
			get 
			{
				return m_AvgDev();
			}
		}
//		public double CoefficientOfDeviation  
//		{
//			get 
//			{
//				return m_CoefDev();
//			}
//		}
		public double Total  
		{
			get 
			{
				return m_Total();
			}
		}
		public double SquareTotal  
		{
			get 
			{
				return m_SqrTotal();
			}
		}
		public int Count  
		{
			get 
			{
				return mvarDataList.Count;
			}
		}


		//private functions
		private double m_AvgDev() 
		{
			int i;
			double temp = 0;
			for ( i = 0 ; i <= this.Count - 1; i++)
			{
				temp +=  System.Math.Abs((double)mvarDataList[i] - m_Mean());
			} //
			return (temp / this.Count);
		}


		private double m_Min() 
		{
			mvarDataList.Sort();

			return (double)mvarDataList[0];

		}

		private double m_Max() 
		{
			mvarDataList.Sort();

			return (double) mvarDataList[this.Count - 1];

		}

		private double m_Mean() 
		{
			//average of all values
			return m_Total() / this.Count;
		}


		private double m_Median() 
		{
			//the middle value of array or average of two if even number

			int i;
			mvarDataList.Sort();
			double temp = 0;

			try 
			{
				switch ( this.Count % 2)
				{
					case 0:
						i = (int)(this.Count / 2);
						temp = ((double)mvarDataList[i] + (double)mvarDataList[i + 1]) / 2;
						break;
					case 1:
						i = (int)((this.Count + 1) / 2);
						temp = (double)mvarDataList[i];
						break;
				}
			} 
			catch 
			{
				temp = 0;
			}

			return temp;

		}


		private double m_SqrTotal() 
		{
			int i;
			double temp = 0;

			for ( i = 0 ; i <= this.Count - 1; i++)
			{
				temp += ((double)mvarDataList[i] * (double)mvarDataList[i]);
			} //

			return temp;

		}

		private double m_Total() 
		{
			int i;//total of values;
			double temp = 0;

			for ( i = 0 ; i <= this.Count - 1; i++)
			{
				temp += (double)mvarDataList[i];
			} //

			return temp;

		}

	}

	//=============================
	public class MoreStats 
	{

		private int mvarCountBornBefore1600; //Number of individuals born before 1600;
		private int mvarCountBorn17thCentury; //Number of individuals born in 17th Century;
		private int mvarCountBorn18thCentury; //Number of individuals born in 18th Century;
		private int mvarCountBorn19thCentury; //Number of individuals born in 19th Century;
		private int mvarCountBorn20thCentury; //Number of individuals born in 20th Century;
		private double mvarAvgNumChildrenPerFamily; //Average Number Of Children;
		private int mvarMaxNumChildren; //Maximum Number Of Children;
		private string  mvarMaxNumChildrenID; //ID of Female With Max Children;
		private int mvarCountDiedBefore20; //Number Of Individuals Who Died Before Age 20;
		private double mvarAvgAgeAtChildBirth; //Average Age At Child Birth;
		private double mvarMaxAgeAtChildBirth; //Maximum Age At Child Birth;
		private double mvarAvgAgeAtDeath; //Average Age At Death;
		private int mvarMaxAgeLived; //Maximum Age Lived;
		private int mvarNumBornInJAN; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInFEB; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInMAR; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInAPR; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInMAY; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInJUN; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInJUL; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInAUG; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInSEP; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInOCT; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInNOV; //Number of Inviduals born in a specific Month;
		private int mvarNumBornInDEC; //Number of Inviduals born in a specific Month;
		private int mvarNumDiedInJAN; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInFEB; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInMAR; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInAPR; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInMAY; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInJUN; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInJUL; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInAUG; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInSEP; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInOCT; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInNOV; //Number of Individuals who died in a specific Month;
		private int mvarNumDiedInDEC; //Number of Individuals who died in a specific Month;

		//Number of individuals born before 1600
		public int CountBornBefore1600  
		{
			get 
			{
				return mvarCountBornBefore1600;
			}
			set 
			{
				mvarCountBornBefore1600 = value;
			}
		}
		//Number of individuals born in 17th Century
		public int CountBorn17thCentury  
		{
			get 
			{
				return mvarCountBorn17thCentury;
			}
			set 
			{
				mvarCountBorn17thCentury = value;
			}
		}
		//Number of individuals born in 18th Century
		public int CountBorn18thCentury  
		{
			get 
			{
				return mvarCountBorn18thCentury;
			}
			set 
			{
				mvarCountBorn18thCentury = value;
			}
		}
		//Number of individuals born in 19th Century
		public int CountBorn19thCentury  
		{
			get 
			{
				return mvarCountBorn19thCentury;
			}
			set 
			{
				mvarCountBorn19thCentury = value;
			}
		}
		//Number of individuals born in 20th Century
		public int CountBorn20thCentury  
		{
			get 
			{
				return mvarCountBorn20thCentury;
			}
			set 
			{
				mvarCountBorn20thCentury = value;
			}
		}
		//Average Number Of Children
		public double AvgNumChildrenPerFamily  
		{
			get 
			{
				return mvarAvgNumChildrenPerFamily;
			}
			set 
			{
				mvarAvgNumChildrenPerFamily = value;
			}
		}
		//Maximum Number Of Children
		public int MaxNumChildren  
		{
			get 
			{
				return mvarMaxNumChildren;
			}
			set 
			{
				mvarMaxNumChildren = value;
			}
		}
		//ID of Female With Max Children
		public string  MaxNumChildrenID  
		{
			get 
			{
				return mvarMaxNumChildrenID;
			}
			set 
			{
				mvarMaxNumChildrenID = value;
			}
		}
		//Number Of Individuals Who Died Before Age 20
		public int CountDiedBefore20  
		{
			get 
			{
				return mvarCountDiedBefore20;
			}
			set 
			{
				mvarCountDiedBefore20 = value;
			}
		}
		//Average Age At Child Birth
		public double AvgAgeAtChildBirth  
		{
			get 
			{
				return mvarAvgAgeAtChildBirth;
			}
			set 
			{
				mvarAvgAgeAtChildBirth = value;
			}
		}
		//Maximum Age At Child Birth
		public double MaxAgeAtChildBirth  
		{
			get 
			{
				return mvarMaxAgeAtChildBirth;
			}
			set 
			{
				mvarMaxAgeAtChildBirth = value;
			}
		}
		//Average Age At Death
		public double AvgAgeAtDeath  
		{
			get 
			{
				return mvarAvgAgeAtDeath;
			}
			set 
			{
				mvarAvgAgeAtDeath = value;
			}
		}
		//Maximum Age Lived
		public int MaxAgeLived  
		{
			get 
			{
				return mvarMaxAgeLived;
			}
			set 
			{
				mvarMaxAgeLived = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInJAN  
		{
			get 
			{
				return mvarNumBornInJAN;
			}
			set 
			{
				mvarNumBornInJAN = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInFEB  
		{
			get 
			{
				return mvarNumBornInFEB;
			}
			set 
			{
				mvarNumBornInFEB = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInMAR  
		{
			get 
			{
				return mvarNumBornInMAR;
			}
			set 
			{
				mvarNumBornInMAR = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInAPR  
		{
			get 
			{
				return mvarNumBornInAPR;
			}
			set 
			{
				mvarNumBornInAPR = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInMAY  
		{
			get 
			{
				return mvarNumBornInMAY;
			}
			set 
			{
				mvarNumBornInMAY = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInJUN  
		{
			get 
			{
				return mvarNumBornInJUN;
			}
			set 
			{
				mvarNumBornInJUN = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInJUL  
		{
			get 
			{
				return mvarNumBornInJUL;
			}
			set 
			{
				mvarNumBornInJUL = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInAUG  
		{
			get 
			{
				return mvarNumBornInAUG;
			}
			set 
			{
				mvarNumBornInAUG = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInSEP  
		{
			get 
			{
				return mvarNumBornInSEP;
			}
			set 
			{
				mvarNumBornInSEP = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInOCT  
		{
			get 
			{
				return mvarNumBornInOCT;
			}
			set 
			{
				mvarNumBornInOCT = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInNOV  
		{
			get 
			{
				return mvarNumBornInNOV;
			}
			set 
			{
				mvarNumBornInNOV = value;
			}
		}
		//Number of Inviduals born in a specific Month
		public int NumBornInDEC  
		{
			get 
			{
				return mvarNumBornInDEC;
			}
			set 
			{
				mvarNumBornInDEC = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInJAN  
		{
			get 
			{
				return mvarNumDiedInJAN;
			}
			set 
			{
				mvarNumDiedInJAN = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInFEB  
		{
			get 
			{
				return mvarNumDiedInFEB;
			}
			set 
			{
				mvarNumDiedInFEB = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInMAR  
		{
			get 
			{
				return mvarNumDiedInMAR;
			}
			set 
			{
				mvarNumDiedInMAR = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInAPR  
		{
			get 
			{
				return mvarNumDiedInAPR;
			}
			set 
			{
				mvarNumDiedInAPR = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInMAY  
		{
			get 
			{
				return mvarNumDiedInMAY;
			}
			set 
			{
				mvarNumDiedInMAY = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInJUN  
		{
			get 
			{
				return mvarNumDiedInJUN;
			}
			set 
			{
				mvarNumDiedInJUN = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInJUL  
		{
			get 
			{
				return mvarNumDiedInJUL;
			}
			set 
			{
				mvarNumDiedInJUL = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInAUG  
		{
			get 
			{
				return mvarNumDiedInAUG;
			}
			set 
			{
				mvarNumDiedInAUG = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInSEP  
		{
			get 
			{
				return mvarNumDiedInSEP;
			}
			set 
			{
				mvarNumDiedInSEP = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInOCT  
		{
			get 
			{
				return mvarNumDiedInOCT;
			}
			set 
			{
				mvarNumDiedInOCT = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInNOV  
		{
			get 
			{
				return mvarNumDiedInNOV;
			}
			set 
			{
				mvarNumDiedInNOV = value;
			}
		}
		//Number of Individuals who died in a specific Month
		public int NumDiedInDEC  
		{
			get 
			{
				return mvarNumDiedInDEC;
			}
			set 
			{
				mvarNumDiedInDEC = value;
			}
		}


	}

}

